package org.promote.hotspot.client.guava;

import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.Subscribe;
import lombok.extern.java.Log;

/**
 * @author enping.jep
 * @date 2023/11/13 17:13
 **/
@Log
public class EventListener {

    private static int eventsHandled;

    @Subscribe
    public void stringEvent(String event) {
        log.info("do event [" + event + "]");
        eventsHandled++;
    }

    @Subscribe
    public void someCustomEvent(CustomEvent customEvent) {
        log.info("do event [" + customEvent.getAction() + "]");
        eventsHandled++;
    }

    //    注册一个 DeadEvent 事件订阅器对于调试或日志记录很有用，因为它可以检测事件分布系统中的错误配置。
    @Subscribe
    public void handleDeadEvent(DeadEvent deadEvent) {
        log.info("unhandled event [" + deadEvent.getEvent() + "]");
        eventsHandled++;
    }

    int getEventsHandled() {
        return eventsHandled;
    }

    void resetEventsHandled() {
        eventsHandled = 0;
    }
}
